package top.xiaoshuaila.moments.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.xiaoshuaila.moments.pojo.Dynamic;
import top.xiaoshuaila.moments.pojo.RespBean;
import top.xiaoshuaila.moments.service.DetailService;
import top.xiaoshuaila.moments.utils.Usersutils;

@Controller
@RequestMapping("detail")
@Api(tags = "动态详情接口")
public class DetailController {
    @Autowired
    private DetailService detailService;
    @ResponseBody
    @GetMapping("getdetail")
    @ApiOperation("获取动态详细信息")
    public RespBean getdetail(long dyid){
        Dynamic dynamic=detailService.getdetail(dyid, Usersutils.getuser().getId());
        if(!dynamic.isShowdetail())
        {
            dynamic.setText("");
            dynamic.setImage("");
        }
        return RespBean.success("success",dynamic);
    }
    @ResponseBody
    @PutMapping("getself")
    @ApiOperation("修改仅自己可见状态")
    public RespBean getself(long dyid){
        return RespBean.success("success",detailService.getself(dyid, Usersutils.getuser().getId()));
    }
    @ResponseBody
    @DeleteMapping("deletedy")
    @ApiOperation("删除动态")
    public RespBean deletedy(long dyid,boolean iszhuan){
        System.out.println(dyid+":"+iszhuan);
        return RespBean.success("success",detailService.deletedy(dyid, Usersutils.getuser().getId(),iszhuan));
    }
    @ResponseBody
    @GetMapping("getzaner")
    @ApiOperation("获取动态点赞列表")
    public RespBean getzaner(long dyid,int page){
        return RespBean.success("success",detailService.getzaner(dyid, Usersutils.getuser().getId(), page));
    }

}
